package main

import (
	"fmt"
	"strings"
)

func main() {
	suffixFun := makeSuffix(".jpg")
	filename1 := suffixFun("abc.jpg")
	fmt.Println(filename1)
	filename2 := suffixFun("bcd")
	fmt.Println(filename2)
}

func makeSuffix(suffix string) func(filename string) string {
	//返回闭包
	return func(filename string) string {
		if strings.HasSuffix(filename, suffix) {
			return filename
		} else {
			return filename + suffix
		}
	}
}
